<template>
  <div>
    <!-- 咨询结果 -->
    <detailBase :user="user" :result="result"></detailBase>
    <!-- 解决方案 -->
    <solution
      :hand-list="handList"
      :hand-list-simple="handListSimple"
      :say-list="sayList"
      :suit-list="suitList"
      :cannot-list="cannotList"
      :food-list="foodList"
      :food-book="foodBook"
      :progress="progress"
    ></solution>
    <!-- 门店推荐 -->
    <recomendDoctor
      :id="id"
      :recommend-product-id="recommendProductId"
      :doctors="doctors"
      :product="product"
      :record_id="record_id"
      @next="$emit('next', {}, 3)"
    ></recomendDoctor>
  </div>
</template>
<script>
import detailBase from './detailBase';
import solution from './solution';
import recomendDoctor from './recomendDoctor';

export default {
  components: {
    detailBase,
    solution,
    recomendDoctor
  },
  props: {
    record_id: {},
    id: {},
    status: {}
  },
  data() {
    return {
      user: {},
      result: {},
      product: [],
      doctors: [],
      recommendProductId: [],
      progress: {
        book: [],
        medicine: [],
        nutrition: [],
        physical: [],
        stick: [],
        fit_tuina: '',
        bubble: []
      },
      handList: {list: []},
      handListSimple: {list: []},
      sayList: {},
      foodList: {},
      foodBook: [],
      commodity: [],
      suitList: [],
      cannotList: []
    };
  },
  watch: {
    record_id: {
      handler(v) {
        if (v) {
          console.log(this.status);
          if (this.status === 'characteristic') {
            this.getCustomResult();
          } else {
            this.getRecord();
            this.getDoctors();
          }
        }
      },
      immediate: true
    }
  },
  methods: {
    // 获取特色项目结果
    getCustomResult() {
      this.$http
        .post(this.$url.getCustomResult, {
          record_id: this.record_id
        })
        .then(res => {
          res.user.u_id = this.id;
          this.result = {
            type: 1,
            disease_name: res.massage.commodity_name
          };
          this.user = res.user;
          this.sayList = res.daily.split('\n').map((item, index) => {
            return {
              id: index,
              doctor_say: item
            };
          });
          this.doctors = res.masseur;
          res.product.other_commodity.forEach(it => {
            it.number = 1;
            it.now_price = it.price;
            it.all_price = it.price;
          });
          this.product = res.product.other_commodity;
          let sum = 0;
          const handData = [];
          res.hand.forEach(item => {
            sum += Number(item.minutes);
            handData.push({
              id: item.id,
              minutes: item.minutes,
              hand: `${item.name + item.minutes}分钟`
            });
          });
          this.handList = {
            list: handData,
            time: sum
          };
        })
        .catch(this.$catch);
    },
    getRecord() {
      this.$http
        .post(this.$url.getRecord, {
          u_id: this.id,
          record_id: this.record_id
        })
        .then(res => {
          res.user.u_id = this.id;
          this.user = res.user;
          this.result = res.result;
          this.progress = res.progress;
          this.handList = res.handList;
          this.handListSimple = res.handListSimple;
          this.sayList = res.sayList;
          this.suitList = res.suit;
          this.cannotList = res.cannot;
          this.foodList = res.foodList;
          this.foodBook = res.foodBook;
          this.recommendProductId = res.product.commodity.map(it => it.id);
          res.product.more = res.product.commodity.concat(res.product.more);
          res.product.more.forEach(it => {
            it.number = 1;
            it.now_price = it.price;
            it.all_price = it.price;
          });
          this.product = res.product.more;
        })
        .catch(this.$catch);
    },
    getDoctors() {
      this.$http
        .post(this.$url.getDoctors)
        .then(res => {
          this.doctors = res;
        })
        .catch(this.$catch);
    }
  }
};
</script>
